package com.tedu.infrastructure;

import com.tedu.dao.ContentMapper;
import com.tedu.domain.bo.ContentBO;
import com.tedu.domain.bo.ContentListBO;
import com.tedu.domain.repository.ContentRepository;
import com.tedu.infrastructure.converter.ContentConverter;
import com.tedu.po.Content;
import com.tedu.protocol.param.ContentParam;
import com.tedu.protocol.param.ContentUpdateParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;
@Repository
public class ContentRepositoryImpl implements ContentRepository {
    @Autowired
    ContentMapper contentMapper;

    @Autowired
    ContentConverter contentConverter;
    @Override
    public Integer insert(ContentParam contentParam) {
        Content content=contentConverter.paramToPo(contentParam);
        int count=contentMapper.insert(content);
        return count;
    }

    @Override
    public Integer updateByPrimaryKeySelective(ContentUpdateParam contentUpdateParam) {
       Content content=contentConverter.paramToPo(contentUpdateParam);
        return contentMapper.updateByPrimaryKeySelective(content);
    }

    @Override
    public Integer deleteById(Integer contentId) {
        return contentMapper.deleteById(contentId);
    }

    @Override
    public List<ContentListBO> list() {
      List<Content> list=contentMapper.list();
        return   contentConverter.poListToBoList(list);
    }

    @Override
    public ContentBO selectByPrimaryKey(Integer contentId) {
        Content content=contentMapper.selectByPrimaryKey(contentId);
        return contentConverter.poToBo(content);
    }

    @Override
    public Integer countByTitle(String title) {
        return contentMapper.countByTitle(title);
    }

}
